# coding=utf-8
import hashlib

# env
# 需要计算md5值的文件
import os
import sys

file_path = os.getenv("JIANMU_FILE_PATH")


def GetFileMd5(filename):
    if not os.path.isfile(filename):
        print("请配置有效文件路径")
        sys.exit(1)
    with open(filename, 'rb') as fp:
        data = fp.read()
    file_md5 = hashlib.md5(data).hexdigest()
    return file_md5


def generateResult(md5_value):
    """生成结果文件"""
    resultFile = open('/tmp/resultFile', 'w', encoding='utf-8')
    result = "{\n\t\"md5_value\" : \"" + md5_value + "\"\n}"
    print("md5_value: " + md5_value)
    resultFile.write(result)
    resultFile.close()


md5_value = GetFileMd5(file_path)
generateResult(md5_value)
